//
//  Define.h
//  WBBaseProject
//
//  Created by 吴斌 on 2017/6/27.
//  Copyright © 2017年 吴斌. All rights reserved.
//

#ifndef Define_h
#define Define_h

#define versionFlag 0  //0为测试版本；1为生产版本

#define Success (WB_IsEquallString(responseObj[@"responseCode"], @"1"))

/*! 在Debug模式显示日志，Release模式关闭日志，普通输出 */
#ifdef DEBUG
#define DebugLog(FORMAT, ...)  NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(FORMAT), ##__VA_ARGS__] );
#else
#define DebugLog( s, ... )
#endif

/*! 用safari打开URL */
#define WB_OpenUrl(urlStr) [BASharedApplication openURL:[NSURL URLWithString:urlStr]]

/*! 字体 */
#define WB_FontSize(fontSize) [UIFont systemFontOfSize:fontSize]

/*! 复制文字内容 */
#define WB_CopyContent(content) [[UIPasteboard generalPasteboard] setString:content]

/*! 随机数据 */
#define WB_RandomData arc4random_uniform(5)

/*! weakSelf */
#define WB_WEAKSELF typeof(self) __weak weakSelf = self;
#define WB_WeakSelf(type)  __weak typeof(type) weak##type = type;

/*! strongSelf */
#define WB_StrongSelf(type)  __strong typeof(type) type = weak##type;

/*! 通知 */
#define WB_NotiCenter [NSNotificationCenter defaultCenter]

/*! NSUserDefaults */
#define WB_UserDefault [NSUserDefaults standardUserDefaults]

/*! 图片 */
#define WB_ImageName(imageName) [UIImage imageNamed:imageName]

/*! 定义 UIImage 对象 */
#define WB_ImageFromBundle(fileName) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]

/*! 获取当前语言 */
#define WB_CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

/*! 警告框-一个按钮【VC】 */
#define WB_SHOW_ALERT(title, msg)  UIAlertController *alert = [UIAlertController alertControllerWithTitle:title  message:msg preferredStyle:UIAlertControllerStyleAlert];\
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {\
}]];\
[self presentViewController:alert animated:YES completion:nil];\

/*! 警告框-一个按钮【View】 */
#define WB_AlertAtView(msg) [[[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil] show];

/*! 设置 view 圆角和边框 */
#define WB_ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

/*! 由角度转换弧度 */
#define WB_DegreesToRadian(x) (M_PI * (x) / 180.0)

/*! 由弧度转换角度 */
#define WB_RadianToDegrees(radian) (radian * 180.0)/(M_PI)

/*! 获取temp */
#define WB_PathTemp NSTemporaryDirectory()

/*! 获取Document */
#define WB_PathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

/*! 获取沙盒 Cache*/
#define WB_PathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

/*! GCD - 一次性执行*/
#define WB_DISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);

/*! GCD - 在Main线程上运行*/
#define WB_DISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);

/*! GCD - 开启异步线程*/
#define WB_DISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlock);

/*! 获取temp */
#define WB_PathTemp NSTemporaryDirectory()

/*! 获取Document */
#define WB_PathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

/*! 获取沙盒 Cache */
#define WB_PathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

/*! GCD - 一次性执行 */
#define WB_DISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);

/*! GCD - 在Main线程上运行 */
#define WB_DISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);

/*! GCD - 在Main线程上延时运行 */
#define WB_DISPATCH_MAIN_Delay_THREAD(delay,mainQueueBlock) dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW,(int64_t)(delay/*延迟执行时间*/ * NSEC_PER_SEC));dispatch_after(delayTime, dispatch_get_main_queue(), mainQueueBlock);

/*! GCD - 开启异步线程 */
#define WB_DISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlock);

/*! 16进制转RGB */
#define WB_HEX_COLOR(x_RGB) [UIColor colorWithRed:((float)((x_RGB & 0xFF0000) >> 16))/255.0 green:((float)((x_RGB & 0xFF00) >> 8))/255.0 blue:((float)(x_RGB & 0xFF))/255.0 alpha:1.0f]

/*! RGB */
#define WB_RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define WB_RGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

/*! 获取APP的名字 */
#define WB_APP_Name [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]

/*! 获取APP的版本号 */
#define WB_APP_Version [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

/*! 获取App短式版本号 */
#define WB_APP_VersionShort [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

/*! 检索本地化字符串 */
#define WBLocalizedString(key, comment) NSLocalizedString(key, comment)

/*! 获取AppDelegate */
#define WB_APPDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])

/*! 获取sharedApplication */
#define WB_SharedApplication [UIApplication sharedApplication]

/*! 空值判断 */
#define WB_IsNilString(__String) (__String==nil || [__String isEqualToString:@""]|| [__String isEqualToString:@"null"])
#define WB_IsNull(__Text) [__Text isKindOfClass:[NSNull class]]
#define WB_IsEquallString(_Str1,_Str2)  [_Str1 isEqualToString:_Str2]

//全局URL
#if versionFlag == 0
//测试环境
//#define BasePath @"http://192.168.102.117:8088/zwp2p"
//#define BasePath @"http://192.168.102.143:8080/zwp2p"//汪

//#define BasePath @"http://192.168.102.143:8080/zwp2p"
//#define BasePath @"http://192.168.1.137:8088/zwp2p"

//#define BasePath @"http://192.168.1.137:8088/zwp2p"
#define BasePath @"http://192.168.102.145:8080/zwp2p"  //孙



#else
//生产环境
#define BasePath @"http://kjydapp.zzlgroup.com"
#endif

#define CommonPath(API) [NSString stringWithFormat:@"%@/%@",BasePath,(API)]

#endif /* Define_h */
